{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import csv\n",
    "import os\n",
    "\n",
    "# 读写文件路径定义\n",
    "file_path_read = os.path.abspath(os.path.join(os.path.dirname(__file__), './res/files/prog/student.csv'))\n",
    "file_path_write = os.path.abspath(os.path.join(os.path.dirname(__file__), './res/files/prog/write.csv'))\n",
    "\n",
    "index = -1\n",
    "lst_read = list()\n",
    "with open(file_path_write, 'w', newline='', encoding='UTF-8') as f_write:\n",
    "    with open(file_path_read, 'r', encoding='UTF-8') as f_read:\n",
    "        writer = csv.writer(f_write)\n",
    "        file = csv.reader(f_read)\n",
    "        for i in file:\n",
    "            lst_read.append(i)\n",
    "        sum_math = 0\n",
    "        for i in lst_read:\n",
    "            index += 1\n",
    "            if index != 0:\n",
    "                sum_math += int(i[1])\n",
    "        print(sum_math)\n",
    "\n",
    "        # index += 1\n",
    "        # if index != 0:\n",
    "        #     lst_temp = [i[0], int(i[1]) + int(i[2]) + int(i[3])]\n",
    "        #     writer.writerow(lst_temp)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 12.28\n",
    "- 计算`9+98+987+...+987654321`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-5-6cd81ccf860f>, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-5-6cd81ccf860f>\"\u001b[1;36m, line \u001b[1;32m5\u001b[0m\n\u001b[1;33m    sum+=num_temp*10+i\u001b[0m\n\u001b[1;37m    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "sum=0        # 累加器\n",
    "num_temp=0   # 当前值\n",
    "for i in range(9,0,-1):\n",
    "    print(\"累加前sum: {0} , 累加值:{1}\".format(sum,num_temp*10+i))\n",
    "    sum+=num_temp*10+i\n",
    "    print(\"累加后sum:\",sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "toc-autonumbering": false
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
